<?php

class sf2s3iGuardBasicSecurityFilter extends sfFilter
{
  public function execute ($filterChain)
  {
    // execute this filter only once
    if ($this->isFirstCall())
    {

      if ($cookie = $this->getContext()->getRequest()->getCookie('sfGuardCookie'))
      {
        $value = unserialize(base64_decode($cookie));
        $c = new Criteria();
        $c->add(GuardUserPeer::REMEMBER_KEY, $value[0]);
        $c->add(GuardUserPeer::LOGIN, $value[1]);
        $user = GuardUserPeer::doSelectOne($c);
          if ($user)
          {
            // sign in
            $this->getContext()->getUser()->signIn($user);
          }
      }
    }
    // execute next filter
    $filterChain->execute();
  }
}